﻿using UnityEngine.UI;

namespace ETHotfix
{
    class LoginUI : HotfixUGuiForm
    {
        public const string PrefabName = "LoginUI";

        public override void OnInit(StarForce.HotfixUGuiForm uiFormLogic, object userdata)
        {
            base.OnInit(uiFormLogic, userdata);
            Log.Info("LoginUI OnInit");
            uiFormLogic.variables.Get<Button>("goButton").onClick.AddListener(() =>
            {
                C2R_Login c2RLogin = new C2R_Login() {Account = "TestAccount", Password = "123456"};


                byte[] bytes = ProtobufHelper.ToBytes(c2RLogin);
                Log.Info("序列化PB大小=" + bytes.Length);

                C2R_Login fromBytes = (C2R_Login) ProtobufHelper.FromBytes(typeof(C2R_Login), bytes, 0, bytes.Length);
                Log.Info("用户名=" + fromBytes.Account);
                Log.Info("密码=" + fromBytes.Password);
                // await Game.UI.OpenUIFormAsync(HallUI.PrefabName.GetUIPath(), "Low",  true);
            });
        }

        public override void OnOpen(object userdata)
        {
            base.OnOpen(userdata);
            Log.Info("LoginUI OnOpen");
        }

        public override void OnClose(object userdata)
        {
            base.OnClose(userdata);
            Log.Info("LoginUI OnClose");
        }

        public override void OnPause()
        {
            base.OnPause();
            Log.Info("LoginUI OnPause");
        }

        public override void OnResume(object userdata)
        {
            base.OnResume(userdata);
            Log.Info("LoginUI OnResume");
        }

        public override void OnCover(object userdata)
        {
            base.OnCover(userdata);
            Log.Info("LoginUI OnCover");
        }

        public override void OnReveal()
        {
            base.OnReveal();
            Log.Info("LoginUI OnReveal");
        }

        public override void OnRefocus(object userData)
        {
            base.OnRefocus(userData);
            Log.Info("LoginUI OnRefocus");
        }

        public override void OnDepthChanged(int uiGroupDepth, int depthInUIGroup)
        {
            base.OnDepthChanged(uiGroupDepth, depthInUIGroup);
            Log.Info("LoginUI OnDepthChanged");
        }
    }
}